package com.weigj.config;

import com.jfinal.config.Constants;
import com.jfinal.config.Handlers;
import com.jfinal.config.Interceptors;
import com.jfinal.config.JFinalConfig;
import com.jfinal.config.Plugins;
import com.jfinal.config.Routes;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.activerecord.CaseInsensitiveContainerFactory;
import com.jfinal.plugin.activerecord.dialect.OracleDialect;
import com.jfinal.plugin.c3p0.C3p0Plugin;
import com.jfinal.render.ViewType;
import com.weigj.controller.CarController;
import com.weigj.intercepter.MyIntercepter;
import com.weigj.model.BaseData;
import com.weigj.model.CarInfo;
import com.weigj.model.CarType;
import com.weigj.model.Dept;
import com.weigj.model.Employee;
import com.weigj.model.HourContract;
import com.weigj.model.HourContractBackSett;
import com.weigj.model.PayInfo;
import com.weigj.model.ReserveHour;
import com.weigj.model.UserDept;

public class WeigjConfig extends JFinalConfig {
	@Override
	public void configConstant(Constants me)
	{
		// 开发者模式
		me.setDevMode(true);
		// 默认视图类型 jsp
		me.setViewType(ViewType.JSP);

	}

	@Override
	public void configRoute(Routes me)
	{
		// action 提交路径hello 默认找的是index方法
		// hello/methodName 找的是methodName的方法
		me.add("/car", CarController.class);
		me.add(new DeptAppRoutes());
		me.add(new WebRoutes());
	}

	@Override
	public void configPlugin(Plugins me)
	{
		// 配置数据库连接
		loadPropertyFile("jdbc.txt");
//		loadPropertyFile("jdbc_local.txt");
		C3p0Plugin c3p0Plugin = new C3p0Plugin(getProperty("jdbcUrl"), getProperty("user"), getProperty("password"));
		// 配置Oracle 驱动
		c3p0Plugin.setDriverClass("oracle.jdbc.driver.OracleDriver");
		me.add(c3p0Plugin);
		ActiveRecordPlugin arp = new ActiveRecordPlugin(c3p0Plugin);
		me.add(arp);
		// 配置oracle方言
		arp.setDialect(new OracleDialect());
		// 配置属性名(字段名)大小写不敏感容器工厂
		arp.setContainerFactory(new CaseInsensitiveContainerFactory());
		//映射数据库与model user 是数据库表的名字 User.class model的类
		arp.addMapping("app_carinfo","infoId", CarInfo.class);
		//-------------场站app用
		arp.addMapping("app_caremployee", "emplid" ,Employee.class);
		arp.addMapping("app_user_dept",UserDept.class);
		arp.addMapping("app_cardept","deptid", Dept.class);
		arp.addMapping("APP_SORTCODESEC","secid",BaseData.class);
		arp.addMapping("APP_RESERVEHOUR",ReserveHour.class);
		arp.addMapping("App_TopCarModel", CarType.class);
		arp.addMapping("app_hourcontract", HourContract.class);
		arp.addMapping("APP_HOURCONTRACTBACKSETT", HourContractBackSett.class);
		arp.addMapping("APP_BACKSETTLEMENTFEE", PayInfo.class);
	}

	// 拦截器
	@Override
	public void configInterceptor(Interceptors me)
	{
		// TODO Auto-generated method stub
		// 配置拦截器 (配置全局的拦截器)
		// 如果想配置只在某个controller上的拦截器在controller上用注解@Before(Interceptor.class)
		// 如果只作用在某个方法上在该方法上加@Before(Interceptor.class)
		me.add(new MyIntercepter());

	}

	@Override
	public void configHandler(Handlers me)
	{
		// TODO Auto-generated method stub

	}

}
